<?php
/**
 * Created by PhpStorm.
 * User: littlenew
 * Date: 18-11-13
 * Time: 下午2:48
 */
    require_once "Basic.php";
    class EventType extends Basic {
        private $tableName = 'timeBlock.eventType';

        public function getAllEventType(){
            $res = $this->dbHandle->select($this->tableName);
            return $res ;
        }

        public function addEventType($argument){
            $checkKeys = [
                'text',
                'bgColor'
            ];
            $insertData = $this->checkArguments($argument, $checkKeys);
            $insertData['isDisabled'] = 0;
            $res = $this->dbHandle->insert($this->tableName, $insertData);

            return $res;
        }

        public function updateEventType($argument){
            $checkKeys = [
                '_id',
                'text',
                'bgColor'
            ];
            $insertData = $this->checkArguments($argument, $checkKeys);
            $where = ['_id' => new MongoDB\BSON\ObjectId($insertData['_id'])];
            unset($insertData['_id']);
            $res = $this->dbHandle->update($this->tableName, $where, $insertData);

            return $res;
        }

        public function disableEventType($argument){
            $checkKeys = [
                '_id'
            ];
            $where = $this->checkArguments($argument, $checkKeys);
            $where['_id'] = new MongoDB\BSON\ObjectId($where['_id']);
            $setData = [
                'isDisabled' => 1
            ];
            $res = $this->dbHandle->update($this->tableName, $where, $setData);

            return $res;
        }
    }